package com.jinlejia.erp.ui.common;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.appcompat.app.AlertDialog;

import com.jinlejia.erp.R;
import com.jinlejia.erp.utils.ACache;

/**
 * 引导弹出层
 */

public class GuideDialog extends AlertDialog {

    private Context context;
    private int imgRes;
    private String key;

    public GuideDialog(Context context, String key, int img) {
        super(context);
        this.context = context;
        this.imgRes = img;
        this.key = key;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        // *** 主要就是在这里实现这种效果的.
        window.setContentView(R.layout.dialog_guide);
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawable(new ColorDrawable());
        window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        ImageView imageView = (ImageView) window.findViewById(R.id.img);
        imageView.setImageResource(imgRes);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ACache.get(context).put(key, key);
                if (dissmissListener != null) {
                    dissmissListener.onDismiss();
                }
                dismiss();
            }
        });

    }

    public interface OnDissmissListener {
        void onDismiss();
    }

    OnDissmissListener dissmissListener;

    public void setDissmissListener(OnDissmissListener listener) {
        this.dissmissListener = listener;
    }

}
